package com.wanhe.base.util;

public class TimeUtil {

	public boolean checkTime(String startTime, String endTime) {

		String s1 = "09:12";
		String s2 = "09:13";

		java.text.DateFormat df = new java.text.SimpleDateFormat("HH:mm");
		java.util.Calendar c1 = java.util.Calendar.getInstance();
		java.util.Calendar c2 = java.util.Calendar.getInstance();

		try {
			c1.setTime(df.parse(startTime));
			c2.setTime(df.parse(endTime));
		} catch (java.text.ParseException e) {
		}

		int result = c1.compareTo(c2);

		if (result == 0) {

			System.out.println("c1相等c2");
			return true;
		} else if (result < 0) {

			System.out.println("c1小于c2");
			return true;
		} else {

			System.out.println("c1大于c2");
			return false;
		}
	}


	public static String secToTime(int time) {
		String timeStr = null;
		int hour = 0;
		int minute = 0;
		int second = 0;
		if (time <=0)
			return "0";
		else {
			minute = time / 60;
			if (minute < 60) {
				second = time % 60;
				timeStr = unitFormat(minute) + "分";
			} else {
				hour = minute / 60;
				if (hour > 500)
					return "99:59:59";
				minute = minute % 60;
				second = time - hour * 3600 - minute * 60;
				timeStr = unitFormat(hour) + "时" + unitFormat(minute) + "分" ;
			}
		}
		return timeStr;
	}

	public static String unitFormat(int i) {
		String retStr = null;
		if (i >= 0 && i < 10)
			retStr = "0" + Integer.toString(i);
		else
			retStr = "" + i;
		return retStr;
	}
}
